nums = [0,1,1,3,4]

def SmallestIndex(target:int) -> int:
    # 大于等于x的最小下标 一般偏左
    left = 0
    ans = len(nums)
    right = len(nums)-1
    while left<=right:
        midd = (left+right) // 2
        if nums[midd] >= target:
            right = midd-1
            ans = midd
        else:
            left = midd +1
    return ans

def LargestIndex(target:int) ->int:
    # 小于等于x的最大下标 一般偏右
    left = 0
    right = len(nums)-1
    ans = 0
    while left<=right:
        midd = (left+right) // 2
        if nums[midd] <= target:
            left = midd+1
            ans = midd
        else:
            right = midd - 1
    return ans

def main():
    result = LargestIndex(5)
    print(result)
    result = SmallestIndex(5)
    print(result)

main()